package com.ytjj.qmyx.mall.enums;


import com.ytjj.qmyx.mall.model.response.DynamicCategoryResponse;

import java.util.ArrayList;
import java.util.List;

public enum DynamicCategoryEnums {

    MAIN_PAGE_QUALITY("MAIN_PAGE_QUALITY",0,"优质测评"),
    MAIN_PAGE_HOT("MAIN_PAGE_HEALTH",6,"本周热榜"),
    MAIN_PAGE_ELECTRIC("MAIN_PAGE_ELECTRIC",1,"智家"),
    MAIN_PAGE_GETFIT("MAIN_PAGE_GETFIT",3,"美妆"),
    MAIN_PAGE_LIFE("MAIN_PAGE_LIFE",4,"美食"),
    MAIN_PAGE_ACC("MAIN_PAGE_ACC",8,"潮搭"),
    MAIN_PAGE_GALLEY("MAIN_PAGE_GALLEY",2,"居家"),
    MAIN_PAGE_HEALTH("MAIN_PAGE_HOT",7,"养生"),
    ;


    private String code;

    private Integer num;

    private String name;

    DynamicCategoryEnums(String code,Integer num, String name) {
        this.code = code;
        this.num = num;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public Integer getNum() {
        return num;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据枚举code获取名称
     * @param
     * @return
     */
    public static String getNameByNum(Integer num){
        DynamicCategoryEnums[] list = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums item : list) {
            if (item.getNum().equals(num)) {
                return item.getName();
            }
        }
        return null;
    }/**
     * 根据枚举code获取名称
     * @param
     * @return
     */
    public static String getCodeByNum(Integer num){
        DynamicCategoryEnums[] list = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums item : list) {
            if (item.getNum().equals(num)) {
                return item.getCode();
            }
        }
        return null;
    }

    /**
     * 根据枚举name获取code
     * @param name
     * @return
     */
    public static Integer getCodeByName(String name) {
        DynamicCategoryEnums[] values = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums value : values) {
            if(value.name.equals(name)) {
                return value.getNum();
            }
        }
        return null;
    }

    public static List<DynamicCategoryResponse> getTypeList() {
        List<DynamicCategoryResponse> list = new ArrayList<>();
        DynamicCategoryEnums[] typeList = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums type : typeList) {
            DynamicCategoryResponse atp = new DynamicCategoryResponse();
            atp.setNum(type.getNum());
            atp.setName(getNameByNum(type.getNum()));
            atp.setCode(getCodeByNum(type.getNum()));
            list.add(atp);
        }
        return list;
    }
}
